import com.alibaba.fastjson.JSON;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Solution {
    public char slowestKey(int[] releaseTimes, String keysPressed) {
        int n = releaseTimes.length;
        // 字符串 charAt(i)
        char ans = keysPressed.charAt(0);
        int maxTime = releaseTimes[0];
        for (int i=1; i<n; i++) {
            char key = keysPressed.charAt(i);
            int time = releaseTimes[i] - releaseTimes[i-1];
            if (time > maxTime || (time == maxTime && key > ans)) {
                ans = key;
                maxTime = time;
            }
        }
        return ans;
    }
}


class MainClass {
    public static void main(String[] args) throws IOException {
        BufferedReader bf =
                new BufferedReader(new InputStreamReader(System.in));
        String str;
        while (null != (str = bf.readLine())) {
            int[] releaseTimes = JSON.parseObject(str, int[].class);
            // String keysPressed = bf.readLine();
            String keysPressed = JSON.parseObject(bf.readLine(), String.class);
            System.out.println(keysPressed);
            System.out.println(new Solution().slowestKey(releaseTimes, keysPressed));
        }
    }
}
